package site.wanjiahao.handler.server;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
import site.wanjiahao.app.Server;

@Slf4j
public class MyChannelDuplexHandler extends ChannelDuplexHandler {
    // c触发用户自定义事件
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        IdleStateEvent event = (IdleStateEvent) evt;
        // 触发读空闲事件
        if (event.state() == IdleState.READER_IDLE) {
            // 关闭客户端连接
            log.debug("客户端出现连接假死，关闭客户端");
            ctx.channel().close();
        }
    }
}
